package com.lineage.server.serverpackets;

import com.lineage.server.datatables.MapsTable;
import com.lineage.server.datatables.QuestMapTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.world.WorldQuest;

public class S_MapID extends ServerBasePacket {
  public S_MapID(L1PcInstance pc, int mapid, boolean isUnderwater) {
    if (!QuestMapTable.get().isQuestMap(pc.getMapId())) {
      if (pc.get_showId() != -1 && WorldQuest.get().isQuest(pc.get_showId()))
        WorldQuest.get().remove(pc.get_showId(), pc); 
      pc.set_showId(-1);
    } 
    int newmapid = MapsTable.get().getCopyMapId(mapid);
    if (newmapid >= 0)
      mapid = newmapid; 
    writeC(206);
    writeH(mapid);
    writeC(isUnderwater ? 1 : 0);
  }
  
  public S_MapID(int mapid) {
    writeC(206);
    writeH(mapid);
    writeC(0);
    writeC(16);
    writeH(248);
    writeC(0);
    writeC(0);
    writeC(0);
    writeC(0);
    writeC(0);
    writeC(16);
    writeC(13);
    writeC(53);
    writeC(197);
  }
  
  public S_MapID(int mapid, boolean isUnderwater) {
    writeC(206);
    writeH(mapid);
    writeC(isUnderwater ? 1 : 0);
    writeC(0);
    writeH(0);
    writeC(0);
    writeD(0);
  }
  
  public byte[] getContent() {
    return getBytes();
  }
}
